package com.open.capacity.common.controller;

import com.open.capacity.common.config.ServerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 导出
 *
 * @author ftquan
 */
@RestController
public class ExportController {
    private static final Logger log = LoggerFactory.getLogger(ExportController.class);


    @Autowired
    private ServerConfig serverConfig;


    /**
     * 导出excel
     *
     * @param fileName    文件名称
     * @param columnJson  列
     * @param dataJson    数据
     * @param exportField 到出列
     */
    @GetMapping("common/exportExcel")
    public void exportExcel(String fileName, String columnJson, String dataJson, String exportField) {
//        //设置导出格式
//        ExcelConfig excelconfig = new ExcelConfig();
//        excelconfig.Title = Server.UrlDecode(fileName);
//        excelconfig.TitleFont = "微软雅黑";
//        excelconfig.TitlePoint = 15;
//        excelconfig.FileName = Server.UrlDecode(fileName) + ".xls";
//        excelconfig.IsAllSizeColumn = true;
//        excelconfig.ColumnEntity = new List<ColumnModel>();
//        //表头
//        List<jfGridModel> columnList = columnJson.ToList < jfGridModel > ();
//        //行数据
//        DataTable rowData = dataJson.ToTable();
//        //写入Excel表头
//        Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
//        if (!string.IsNullOrEmpty(exportField)) {
//            string[] exportFields = exportField.Split(',');
//            foreach(var field in exportFields)
//            {
//                if (!exportFieldMap.ContainsKey(field)) {
//                    exportFieldMap.Add(field, "1");
//                }
//            }
//        }
//
//        foreach(jfGridModel columnModel in columnList)
//        {
//            if (exportFieldMap.ContainsKey(columnModel.name) || string.IsNullOrEmpty(exportField)) {
//                excelconfig.ColumnEntity.Add(new ColumnModel() {
//                    Column =columnModel.name,
//                    ExcelColumn =columnModel.label,
//                    Alignment =columnModel.align,
//                });
//            }
//        }
//        ExcelHelper.ExcelDownload(rowData, excelconfig);
    }
}
